import Vue from 'vue'
import Vuex from 'vuex'
import http from '../api/http.js'
Vue.use(Vuex)
export default new Vuex.Store({
	//全局data
	state:{
		userInfo:{},	//用户信息
		hasLogin:false,	//是否登录
		baseUrl:'http://localhost:3000',
		location:"",	//当前的经纬度;格式(lat,lng)
		currentCity:"武汉",	//当前定位的城市
		address:"",	//当前定位的具体地址
		addrObj:{
			location:"",
			address:""
		},//需要添加的地址
	},
	
	mutations:{
		//登录
		 login(state,obj){
			state.userInfo = obj;
			state.hasLogin = true;
			uni.setStorage({
				key:'userInfo',
				data:obj
			});
		},
		//退出
		 logout(state){
			//退出登录
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key:'userInfo'
			});
		},
		//更换头像
		changeAvatar(state,avatar){
			state.userInfo.avatar = avatar;
			let obj = state.userInfo;
			uni.setStorage({
				key:'userInfo',
				data:obj
			});
		},
		
		//更换当前城市
		changeCurrentcity(state,city){
			state.currentCity = city;
		},
		
		//更换当前地址
		changeAddress(state,address){
			state.address = address;
		},
		
		//更换当前经纬度location
		changeLocation(state,location){
			state.location = location;
		},
		
		//添加选择的城市
		selectAddress(state,obj){
			state.addrObj.address = obj.address,
			state.addrObj.location = obj.location;
		},
		//删除选择的城市
		deleteAddress(state){
			state.addrObj.address = "",
			state.addrObj.location = "";
		}
	}
})